const express = require('express');
const pool = require("../pool.js");
const router = express.Router();
module.exports = router;
// 登录验证
router.get('/check_user', (req, res) => {
	let n = req.query.phone;
	let sql = "select * from ff_user where phone=?"
	if (n = '') {
		res.send("null");
		return;
	}
	pool.query(sql, n, (err, result) => {
		if (err) throw err;
		if (!result.length == 0) {
			res.send({
				code: 200,
				msg: "success"
			});
		} else {
			res.send({
				code: 201,
				msg: "no-success"
			});
		}

	});
});
// 注册验证
router.post("/reg", (req, res) => {
	var obj = req.body;
	if (!obj.phone) {
		res.send({
			code: 401,
			msg: "not null"
		});
		return;
	}
	pool.query("select * from ff_user where phone=?", obj.phone, (err, result) => {
		if (err) {
			throw err;
			return;
		}

		if (!result.length == 0) {
			res.send({
				code: 401,
				msg: "exist"
			});
		} else {
			res.send({
				code: 200,
				msg: "no-exist"
			});
			pool.query("insert into ff_user (fid,phone) values (?,?)", [obj.fid, obj.phone], (err,
				result) => {
				if (err) {
					throw err;
					return;
				}
				// if (!result.length) {
				// 	res.send("成功");
				// }
			})

		}

	})
})
